package com.edu.modules.baseinfo.web;

import com.edu.modules.baseinfo.service.LessonService;
import com.edu.modules.baseinfo.service.TeacherService;
import com.sari.common.service.AliVideo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;

/**views
 * 管理后台Controller
 */
@CrossOrigin
@Controller
@RequestMapping(value = "views")
public class ViewsController {

    @Autowired
    private TeacherService teacherService;

    @RequestMapping(value = "/login")
    public String login() {
        return "jsp/login";
    }

    @RequestMapping(value = "/mainPage")
    public String getMainPage() {
        return "jsp/mainPage";
    }

    @RequestMapping(value = "/admin")
    public String getAdmin() {
        return "jsp/admin";
    }

    @RequestMapping(value = "/teacher")
    public String getTeacher(Model model) {

        model.addAttribute("lessons", teacherService.getTeachersLesson());
        return "jsp/teacher";
    }

    @RequestMapping(value = "/student")
    public String getStudent() {
        return "jsp/student";
    }

    @RequestMapping(value = "/lesson")
    public String getLesson(Model model) {

        model.addAttribute("teachers", teacherService.getTeacherName());
        return "jsp/lesson";
    }

    @RequestMapping(value = "/order")
    public String getOrder() {
        return "jsp/order";
    }

    @RequestMapping(value = "/lessonRecord")
    public String getLessonRecord() {
        return "jsp/lessonRecord";
    }

    @RequestMapping(value = "/teacherHomework")
    public String getTeacherHomework() {
        return "jsp/teacherHomework";
    }

    @RequestMapping(value = "/studentHomework")
    public String getStudentHomework() {
        return "jsp/studentHomework";
    }

    @RequestMapping(value = "/account")
    public String getAccount() {
        return "jsp/account";
    }

    @RequestMapping(value = "/pwd")
    public String modifyPwd() {
        return "jsp/passwordModification";
    }

    @RequestMapping(value = "/teacherLessonStatistics")
    public String teacherLessonStatistics(Model model) {

        model.addAttribute("teachers", teacherService.getTeachers());
        return "jsp/teacherLessonStatistics";
    }

    @RequestMapping(value = "/teacherClassStatistics")
    public String teacherClassStatistics(Model model) {

        model.addAttribute("teachers", teacherService.getTeachers());
        return "jsp/teacherClassStatistics";
    }

    @RequestMapping(value = "/studentLessonStatistics")
    public String studentLessonStatistics() {

        return "jsp/studentLessonStatistics";
    }

    @RequestMapping(value = "/index")
    public String index() {
        return "jsp/index";
    }

    @RequestMapping(value = "/vodPlayer")
    public String vodPlayer(String videoId, Model model) throws IOException{

        String playauth = AliVideo.getPlayAuth(videoId);
        model.addAttribute("videoId", videoId);
        model.addAttribute("playauth", playauth);

        return "jsp/video";
    }

    @RequestMapping(value = "/teacherEvaluate")
    public String teacherEvaluate() {
        return "jsp/teacherEvaluate";
    }
}